package com.qiuyang.controller;

import com.qiuyang.pojo.Blog;
import com.qiuyang.pojo.Tag;
import com.qiuyang.service.show.ShowTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class ShowTagController {
    @Autowired
    private ShowTagService showTagService;

    @RequestMapping("/tag")
    public String tags(Model model){
        model.addAttribute("tags",showTagService.findAllTag());
        return "blog/tag";
    }



    @RequestMapping("/tag/{tagsId}")
    public String BlogsByTagsId(@PathVariable String tagsId,Model model){
        model.addAttribute("tags",showTagService.findAllTag());
        List<Long> blogTags = showTagService.findBlogTags(tagsId);
        List<Blog> blogByBlogsId = new ArrayList<>();
        for (Long blogsId:blogTags
        ) {
            blogByBlogsId.add(showTagService.findBlogByBlogsId(blogsId));
        }
        model.addAttribute("blog",blogByBlogsId);
        return "blog/tag";
    }


}
